import cloud from "@tbmp/mp-cloud-sdk";

export default {
  uploadFile(option) {
    return new Promise((resolve, reject) => {
      cloud.file
        .uploadFile(option)
        .then(async data => {
          resolve(data);
        })
        .catch(e => {
          reject(e);
        });
    });
  },
  ctx2Path(ctx, width, height, destWidth, destHeight) {
    return new Promise((resolve, reject) => {
      ctx.toTempFilePath({
        width: width,
        destWidth: destWidth || width,
        destHeight: destHeight || height,
        height: height,
        async success(res) {
          // eslint-disable-next-line no-undef
          my.getImageInfo({
            src: res.apFilePath,
            async success(res) {
              resolve(res);
            },
            fail(e) {
              reject(e);
            },
          });
        },
        fail(e) {
          reject(e);
        },
      });
    });
  },
};
